package com.my.mytest.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.os.Bundle;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;

import com.my.mytest.R;
import com.my.mytest.adapter.UpAnimAdapter;
import com.my.mytest.bean.ImageData;
import com.my.mytest.util.SpaceItemDecoration;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class RvAnimActivity extends AppCompatActivity {
    private RecyclerView rv_anim_up;
    private static final Integer[] CATS = new Integer[]{
            R.mipmap.p1,
            R.mipmap.p2,
            R.mipmap.p3,
            R.mipmap.p4,
            R.mipmap.p5,
            R.mipmap.p6,
            R.mipmap.p7,
            R.mipmap.p8,
            R.mipmap.p9,
            R.mipmap.p10,
            R.mipmap.p11,
            R.mipmap.p12,
            R.mipmap.p13,
            R.mipmap.p14,
            R.mipmap.p15,
            R.mipmap.p16,
            R.mipmap.p17,
            R.mipmap.p18,
            R.mipmap.p19,
            R.mipmap.p20,
            R.mipmap.p21,
    };

    private List<Integer> data;
    private UpAnimAdapter adapter;
    private List<ImageData> imgData = new ArrayList<>();

    private int flag = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rv_anim_up);

        data = Arrays.asList(CATS);

        initData();
        initView();
    }

    private void initData() {
        flag = getIntent().getIntExtra("flag", 0);
    }

    private void initView() {
        rv_anim_up = findViewById(R.id.rv_anim_up);

        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
        rv_anim_up.setLayoutManager(layoutManager);
        rv_anim_up.addItemDecoration(new SpaceItemDecoration(this, 64, 2));// 添加分割线


        adapter = new UpAnimAdapter(this);
        rv_anim_up.setAdapter(adapter);


        for (int i = 0; i < data.size(); i++) {
            imgData.add(new ImageData(data.get(i), 0));
        }

        adapter.setData(imgData, rv_anim_up, flag);
    }

}